package com.sss.portalrimac.web.registro.viewmodel;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.sss.portalrimac.domain.Cliente;
import com.sss.portalrimac.infraestructure.util.DateUtil;

public class RegistroCommand
{
	public static final int EDAD_MIN = 18;
	public static final int EDAD_MAX = 120;
	private Cliente cliente;
	private String dia;
	private String mes;
	private String anio;
	private List<ComboBoxBean> listDia;
	private List<ComboBoxBean> listMes;
	private List<ComboBoxBean> listAnio;
	private String divOlvidoContrasenaDisplay;

	public RegistroCommand()
	{
		this.divOlvidoContrasenaDisplay = "none";
		this.setCliente(new Cliente());
		this.setListDia(generarListaDia());
		this.setListAnio(generarListaAnio());
	}

	public Cliente getCliente()
	{
		return cliente;
	}

	public Cliente getParseCliente() throws Exception
	{
		parseCliente();
		return cliente;
	}

	public void setCliente(Cliente cliente)
	{
		this.cliente = cliente;
	}

	public String getDia()
	{
		return dia;
	}

	public void setDia(String dia)
	{
		this.dia = dia;
	}

	public String getMes()
	{
		return mes;
	}

	public void setMes(String mes)
	{
		this.mes = mes;
	}

	public String getAnio()
	{
		return anio;
	}

	public void setAnio(String anio)
	{
		this.anio = anio;
	}

	public List<ComboBoxBean> generarListaDia()
	{
		List<ComboBoxBean> dias = new ArrayList<ComboBoxBean>();
		for (int i = 1; i <= 31; i++)
		{
			dias.add(new ComboBoxBean(String.format("%02d", i) + "", String.format("%02d", i) + ""));
		}
		return dias;
	}

	public List<ComboBoxBean> generarListaAnio()
	{
		Date fechaActual = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(fechaActual);
		int anio = calendar.get(Calendar.YEAR);
		List<ComboBoxBean> anios = new ArrayList<ComboBoxBean>();
		for (int i = anio - RegistroCommand.EDAD_MIN; i >= anio - RegistroCommand.EDAD_MAX; i--)
		{
			anios.add(new ComboBoxBean(i + "", i + ""));
		}
		return anios;
	}

	private void parseCliente() throws Exception
	{
		cliente.setFechaNacimiento(DateUtil.stringDDMMYYYYToDate(getDia() + "/" + getMes() + "/" + getAnio()));
		cliente.setFechaRegistroPortal(new Date());
	}

	public void setDivOlvidoContrasenaDisplay(String divOlvidoContrasenaDisplay)
	{
		this.divOlvidoContrasenaDisplay = divOlvidoContrasenaDisplay;
	}

	public String getDivOlvidoContrasenaDisplay()
	{
		return divOlvidoContrasenaDisplay;
	}

	public void setListDia(List<ComboBoxBean> listDia)
	{
		this.listDia = listDia;
	}

	public List<ComboBoxBean> getListDia()
	{
		return listDia;
	}

	public void setListMes(List<ComboBoxBean> listMes)
	{
		this.listMes = listMes;
	}

	public List<ComboBoxBean> getListMes()
	{
		return listMes;
	}

	public void setListAnio(List<ComboBoxBean> listAnio)
	{
		this.listAnio = listAnio;
	}

	public List<ComboBoxBean> getListAnio()
	{
		return listAnio;
	}
}
